<?php
class RM_Admin_VideoController extends RM_Controller {
    
   public function loadJsonAction(){

       //video

        $unit_id = $this->_getParam('id');

        $videoDAO = new RM_Video();
        $videoInfo = $videoDAO->fetchByUnit($unit_id)->toArray();

        return array(
            'data' => $videoInfo,
            'encoded' => false
        );
    }

    public function updateJsonAction(){

        $data = $this->_getParam('rm_video_edit');

        

        if ($data['feed_id']==""){
            // insert new

            // reassign the values to a different array for the rm_unit_video table
            $feedData['embedcode'] = $data['embedcode'];
            $feedData['provider'] = $data['provider'];
            unset($data['embedcode']);
            unset($data['provider']);
            unset($data['feed_id']);

            $daoVideo = new RM_Video;
            $feedData['feed_id'] = $daoVideo->insert($data);

            $daoUnitVideo = new RM_UnitVideo;
            $daoUnitVideo->insert($feedData);

        } else {
            // update
            
            $feed_id=$data['feed_id'];

            unset($data['id']);
            unset($data['feed_id']);
            unset($data['unit_id']);

            $daoUnitVideo = new RM_UnitVideo;
            $daoUnitVideo->update($data, "feed_id='".$feed_id."'");
        }

        return array(
        'data' => array('success' => 'true', 'msg' => '')
        );

    }
}